package cn.qn.common.util;

import cn.qn.common.constants.AppConstants;
import cn.qn.moudle.user.AppUser;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;

/**
 * Created by nishu on 2018/4/24.
 */
@Component
public class UserSubjectUtil {
    @Resource
    private RedisTemplate<String,AppUser> redisTemplate;


    private static RedisTemplate<String,AppUser> staticRedisTemplate;

    @PostConstruct
    public void init(){
        staticRedisTemplate=redisTemplate;
    }

    public static AppUser getAppUser(String authorization){
        return staticRedisTemplate.opsForValue().get(AppConstants.APP_TOKEN_PREFIX +authorization);
    }

    public static void removeAppUser(String authorization){
        staticRedisTemplate.delete(AppConstants.APP_TOKEN_PREFIX +authorization);
    }

}
